package TestApp;

import Sources.*;
import Users.User;

import static TestApp.Dialog.*;

/**
 * @author Myhaylo Kotsyuruba
 * @version v.1.4   14.03.13
 */

public class TestApp {
    private SourceUser mySourceUser;
    private TestCreator myTestCreator;

    public TestApp() {
        mySourceUser = new SourceUser();
        myTestCreator = new TestCreator();
    }

    public static void main(String[] args) {
        TestApp myApp = new TestApp();
        myApp.run();
    }

    public void run() {
        showWelcome();
        while (wantLogin()) {
            User user = loginUser();
            workWith(user);
        }
    }

    private User loginUser() {
        String userName = IOSystem.getAnswer("\nPlease, enter Your login: ");
        return mySourceUser.getUser(userName);
    }

    private void workWith(User user) {
        while (true) {
            switch (getUserPlan()) {
                case 1:
                    getTested(user);
                    break;
                case 2:
                    user.showAllResults();
                    break;
                default: return;
            }
        }
    }

    private void getTested(User user) {
        String[] strings = SourceStrings.getStrings();
        Test test = myTestCreator.createTest(strings);
        user.getTested(test);
        IOSystem.writeToFile(user.getName(), user.getAllTestReport());
    }
}
